Skip to content

Refactor: make host_build_graph's includes say what each file uses - #2101

Merged
ChaoZheng109 merged 1 commit into
hw-native-sys:mainfrom
poursoul:refactor/make-host-build-graphs-includes-say-what-each
Sep 3, 2026
Merged

Refactor: make host_build_graph's includes say what each file uses#2101
ChaoZheng109 merged 1 commit into
hw-native-sys:mainfrom
poursoul:refactor/make-host-build-graphs-includes-say-what-each

Conversation

@poursoul

@poursoul poursoul commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Every translation unit and header under host_build_graph now includes what it uses and nothing else, so a reader can tell a file's dependencies from its include block instead of following a chain of headers that happened to carry something along.

105 includes removed, 51 added — a net 54 fewer — where the using file had been relying on a transitive path.

Three headers had become unofficial hubs

runtime_types.h carried runtime_status.h and aicore_completion_mailbox.h; common.h carried assert_compat.h; and runtime.h carried <stdio.h> and <string.h> under comments that named symbols — "for fprintf, printf", "for memset"runtime.h itself never uses. None of the three used what it carried; consumers did, without naming it. All are gone, and the files reaching SIMPLER_ERROR_*, always_assert, debug_assert and std::memset through them now include those headers directly.

Same shape at smaller scale: tensormap.h takes tensor_create_info.h, async_wait.h takes aicore_completion_mailbox_types.h, runtime_maker.cpp takes host_phase_kind.h, sdma_completion_scheduler.h takes constants.h and cache_maintenance.h.

One include moves inside its conditional, one moves ahead of it

scheduler.h's aicpu/device_time.h: all eight uses of get_sys_cnt_aicpu sit inside SIMPLER_*_PROFILING blocks, so an unconditional include claimed a dependency the file only has when timing is compiled in. Its comment also claimed early-dispatch doorbell timing used it, which no call site does.

The same file now includes profiling_config.h ahead of that conditional rather than receiving the levels through runtime_types.h. The order happens to work today, but an #if on an undefined macro evaluates to 0 — so a profiling block that reaches its levels transitively switches itself off silently the day someone tidies the header it came through. That is the failure mode the table below exists to avoid, and the file was subject to it.

Four kinds kept despite the tooling saying otherwise

A pass with clang-tidy's misc-include-cleaner produced the candidate list, but it reads several correct includes as unused. Each of these was confirmed by deleting it and watching the build:

header what the tool cannot see
profiling_config.h ×5 supplies the macros the #if conditions test — putting it inside one would make the condition evaluate to 0 and silently disable the feature
runtime_core.h in scheduler_cold_path.cpp ×2 rt->scheduler needs the complete RuntimeContext; the tool finds a forward declaration first and stops
aicore.h + aicore_profiling_state.h AICore builtins (read_reg, get_physical_core_id, ...) a host-side parser cannot resolve
two pto async .hpp same — pto::comm::sdma::detail::* behind __ubuf__ types

Why four build configurations

A header that only matters inside #if SIMPLER_DFX or a profiling block is invisible to a single build — deleting it passes, and the breakage only appears when someone turns that flag on. So every batch was checked against default, SIMPLER_ORCH_PROFILING, SIMPLER_SCHED_PROFILING and SIMPLER_DFX=0, across both architectures and both platform variants.

That is also why "the build passed" was not treated as evidence of completeness: a missed include leaves the build green by definition. Completeness came from re-running the scan until it reported nothing but the known exceptions.

Test

  • 4 profiling configurations × 4 platforms (a2a3/a5 × sim/onboard), zero warnings; tensormap_and_ringbuffer rebuilt on all 4 platforms to confirm the shared headers are unaffected
  • ctest: 128/128
  • Scene tests: a2a3sim 10 passed, a5sim 13 passed — the only thing that exercises the orchestration .so, which the orchestration_api.h changes reach

Rebased onto #2090, which rewrote a5's aicpu_executor.cpp. Every include this PR had removed from that file was re-checked against the new code: <cinttypes> (PRIu64), aicpu/device_time.h, chip_swimlane_collector_aicpu.h, platform_regs.h and platform_config.h are now genuinely used and stay; <unistd.h>, <algorithm>, sys/mman.h, args_dump_aicpu.h and pmu_collector_aicpu.h are not and are removed.

Split out of #2098, which keeps the two behavioural changes it was mixed with.

@coderabbitai

coderabbitai Bot commented Sep 2, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 4a4b047c-cbfa-4fc5-8b24-6c3e38babd48

📥 Commits

Reviewing files that changed from the base of the PR and between 1f3995c and c8a30e9.

📒 Files selected for processing (48)
  • src/a2a3/runtime/host_build_graph/aicpu/aicpu_executor.cpp
  • src/a2a3/runtime/host_build_graph/host/runtime_maker.cpp
  • src/a2a3/runtime/host_build_graph/orchestration/common.cpp
  • src/a2a3/runtime/host_build_graph/orchestration/orchestration_api.h
  • src/a2a3/runtime/host_build_graph/runtime/aicore_completion_mailbox.h
  • src/a2a3/runtime/host_build_graph/runtime/async_wait.h
  • src/a2a3/runtime/host_build_graph/runtime/backend/sdma/sdma_completion_scheduler.h
  • src/a2a3/runtime/host_build_graph/runtime/scheduler/scheduler.h
  • src/a2a3/runtime/host_build_graph/runtime/scheduler/scheduler_cold_path.cpp
  • src/a2a3/runtime/host_build_graph/runtime/scheduler/scheduler_completion.cpp
  • src/a2a3/runtime/host_build_graph/runtime/scheduler/scheduler_context.h
  • src/a2a3/runtime/host_build_graph/runtime/scheduler/scheduler_dispatch.cpp
  • src/a2a3/runtime/host_build_graph/runtime/scheduler/scheduler_types.h
  • src/a5/runtime/host_build_graph/aicpu/aicpu_executor.cpp
  • src/a5/runtime/host_build_graph/host/runtime_maker.cpp
  • src/a5/runtime/host_build_graph/orchestration/common.cpp
  • src/a5/runtime/host_build_graph/orchestration/orchestration_api.h
  • src/a5/runtime/host_build_graph/runtime/aicore_completion_mailbox.h
  • src/a5/runtime/host_build_graph/runtime/async_wait.h
  • src/a5/runtime/host_build_graph/runtime/backend/sdma/sdma_completion_scheduler.h
  • src/a5/runtime/host_build_graph/runtime/scheduler/scheduler.h
  • src/a5/runtime/host_build_graph/runtime/scheduler/scheduler_cold_path.cpp
  • src/a5/runtime/host_build_graph/runtime/scheduler/scheduler_completion.cpp
  • src/a5/runtime/host_build_graph/runtime/scheduler/scheduler_context.h
  • src/a5/runtime/host_build_graph/runtime/scheduler/scheduler_dispatch.cpp
  • src/a5/runtime/host_build_graph/runtime/scheduler/scheduler_types.h
  • src/common/host_build_graph/common.h
  • src/common/host_build_graph/completion_token.h
  • src/common/host_build_graph/dep_gen_host_graph.h
  • src/common/host_build_graph/device/graph_execution.cpp
  • src/common/host_build_graph/host/graph_recorder_pool.cpp
  • src/common/host_build_graph/host/host_phase_trace.cpp
  • src/common/host_build_graph/host/orchestrator.cpp
  • src/common/host_build_graph/host/runtime_core.cpp
  • src/common/host_build_graph/host/tensormap.cpp
  • src/common/host_build_graph/orchestrator.h
  • src/common/host_build_graph/runtime.h
  • src/common/host_build_graph/runtime_core.h
  • src/common/host_build_graph/runtime_types.h
  • src/common/host_build_graph/shared/runtime.cpp
  • src/common/host_build_graph/shared/shared_memory.cpp
  • src/common/host_build_graph/shared_memory.h
  • src/common/host_build_graph/task_allocator.h
  • src/common/host_build_graph/tensor.h
  • src/common/host_build_graph/tensor_create_info.h
  • src/common/host_build_graph/tensormap.h
  • src/common/host_build_graph/types.h
  • tests/ut/cpp/common/test_hbg_graph_cache.cpp
💤 Files with no reviewable changes (15)
  • src/common/host_build_graph/device/graph_execution.cpp
  • src/common/host_build_graph/runtime.h
  • src/common/host_build_graph/host/host_phase_trace.cpp
  • src/common/host_build_graph/dep_gen_host_graph.h
  • src/a5/runtime/host_build_graph/runtime/aicore_completion_mailbox.h
  • src/common/host_build_graph/shared/runtime.cpp
  • src/a5/runtime/host_build_graph/runtime/backend/sdma/sdma_completion_scheduler.h
  • src/a5/runtime/host_build_graph/aicpu/aicpu_executor.cpp
  • src/common/host_build_graph/host/graph_recorder_pool.cpp
  • src/a2a3/runtime/host_build_graph/aicpu/aicpu_executor.cpp
  • src/common/host_build_graph/runtime_core.h
  • src/common/host_build_graph/tensor.h
  • src/common/host_build_graph/completion_token.h
  • src/a2a3/runtime/host_build_graph/runtime/aicore_completion_mailbox.h
  • src/common/host_build_graph/common.h

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

This change removes unused and transitive headers across common, A2A3, and A5 host build graph code. It adds direct assertion and runtime-status dependencies. Profiling-specific device-time inclusion is now conditional.

Changes

Host build graph include cleanup

Layer / File(s) Summary
Common runtime header contracts
src/common/host_build_graph/*.h
Common headers use focused dependencies. Assertion and runtime-status definitions are included directly where required.
Common runtime implementation includes
src/common/host_build_graph/{device,host,shared}/*, tests/ut/cpp/common/test_hbg_graph_cache.cpp
Implementation and test files remove unused headers and add direct dependencies for runtime status, logging, and runtime types.
A2A3 and A5 runtime scheduler includes
src/a2a3/runtime/host_build_graph/{orchestration,runtime}/..., src/a5/runtime/host_build_graph/{orchestration,runtime}/...
Scheduler and orchestration files narrow platform, mailbox, standard-library, assertion, and runtime-status includes. Profiling device-time inclusion is conditional.
A2A3 and A5 entry-point includes
src/{a2a3,a5}/runtime/host_build_graph/{aicpu,host}/...
Executor and runtime-maker files replace broad include sets with focused runtime, logging, assertion, phase, and completion dependencies.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to c8a30

This refactor makes file dependencies explicit without changing runtime behavior; the stated configurations and tests pass, and no actionable merge-blocking risk remains.

Poem

A rabbit reads each line,
The patch grows clear beneath the moon,
Small changes hop in place,
Tests guard the garden path,
Reviews bloom before the dawn.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 33 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the primary change: direct, usage-based include dependencies in host_build_graph.
Description check ✅ Passed The description directly explains the include refactor, dependency-hub removal, conditional include change, retained exceptions, and validation results.
  • Fix all pre-merge checks with AI

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@poursoul
poursoul force-pushed the refactor/make-host-build-graphs-includes-say-what-each branch 3 times, most recently from 9681612 to a78a501 Compare September 3, 2026 01:24
Every translation unit and header under host_build_graph now includes what it
uses and nothing else, so a reader can tell a file's dependencies from its
include block rather than by following a chain of headers that happened to carry
something along. 105 includes are removed and 51 added, a net 54 fewer.

Three headers were acting as unofficial hubs. runtime_types.h carried
runtime_status.h and aicore_completion_mailbox.h for consumers that never named
them; common.h carried assert_compat.h the same way; and runtime.h carried
<stdio.h> and <string.h> under comments -- "for fprintf, printf", "for memset" --
naming symbols runtime.h itself never uses. All are gone, and the files reaching
SIMPLER_ERROR_*, always_assert, debug_assert and std::memset through them now
include those headers directly. Same for the smaller cases: tensormap.h takes
tensor_create_info.h, async_wait.h takes aicore_completion_mailbox_types.h,
runtime_maker.cpp takes host_phase_kind.h, sdma_completion_scheduler.h takes
constants.h and cache_maintenance.h.

scheduler.h's aicpu/device_time.h moves inside the profiling conditional. Every
one of its eight uses of get_sys_cnt_aicpu sits in a SIMPLER_*_PROFILING block,
so an unconditional include claimed a dependency the file only has when timing
is compiled in. Its comment claimed early-dispatch doorbell timing used it too,
which no call site does. The same file now includes profiling_config.h ahead of
that conditional rather than receiving the levels through runtime_types.h: an #if
on an undefined macro evaluates to 0, so a profiling block that reaches its
levels transitively switches itself off silently the day that path changes.

Four kinds of header that a tooling pass reads as unused are kept, each for a
reason the tool cannot see: profiling_config.h supplies the macros the #if
conditions test, so including it under one of them would evaluate to 0 and
silently disable the feature; runtime_core.h in scheduler_cold_path.cpp supplies
the complete RuntimeContext that rt->scheduler needs, where the forward
declaration the tool finds first is not enough; and aicore.h,
aicore_profiling_state.h and the two pto async .hpp files supply AICore builtins
a host-side parser cannot see.

Verified by building all four profiling configurations -- default,
SIMPLER_ORCH_PROFILING, SIMPLER_SCHED_PROFILING and SIMPLER_DFX=0 -- across both
architectures and both platform variants, since a header that only matters to a
conditional block is invisible to a single build.
@ChaoZheng109
ChaoZheng109 merged commit 5cb790c into hw-native-sys:main Sep 3, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants